<template>
	<view>
		<view class="row b-b">
			<text class="tit">名称</text>
			<input class="input" type="text" v-model="name" placeholder="请输入商户名称" placeholder-class="placeholder" />
		</view>

		<view class="row b-b">
			<text class="tit">店主姓名</text>
			<input class="input" type="text" v-model="owner" placeholder="请输入店主姓名" placeholder-class="placeholder" />
		</view>

		<view class="row b-b">
			<text class="tit">联系方式</text>
			<input class="input" type="text" v-model="mobile" placeholder="请输入联系方式" placeholder-class="placeholder" />
		</view>

		<view class="row b-b">
			<text class="tit">简介</text>
			<textarea auto-height disable-default-padding auto-focus show-confirm-bar placeholder="简介" class="input"
				v-model="introduce"></textarea>
		</view>

		<view class="row b-b">
			<view class="tit">封面图
			</view>
			<view class="" style="width: 140upx;">
				<robby-image-upload :src="cover_img" :width="width" :height="height" :lineheight="lineheight"
					:borderRadius="borderRadius"></robby-image-upload>
			</view>
		</view>

		<view class="" style="height: 20rpx;"></view>

		<view class="row b-b">
			<text class="tit">图集</text>
			<view class="">
				<uploads></uploads>
			</view>
		</view>

		<view class="add-btn" @tap="lssue">发布</view>
	</view>
</template>

<script>
	import uploads from "@/components/uploads1.vue";
	import robbyImageUpload from '@/components/robby-image-upload/robby-image-upload4.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				title: '商家发布',
				height: '140rpx',
				lineheight: '140rpx',
				width: '140rpx',
				borderRadius: '',
				name: '',
				owner: '',
				mobile: '',
				VideosData: '',
				introduce: '',
				cover_img: '/static/img/videos/WechatI.png'
			}
		},
		components: {
			robbyImageUpload,
			uploads
		},
		computed: {
			...mapState(['hasLogin'])
		},

		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			uni.$on('changeBusinessImgs', (options) => {
				this.VideosData = JSON.stringify(options)
			})

			uni.$on('changeBusinessCover', (option) => {
				this.cover_img = option.path
			})
		},
		methods: {
			...mapMutations(['login', 'logout']),

			async lssue() {
				if (!this.name) {
					this.$api.msg('请输入商户名称')
					return false;
				}
				if (!this.owner) {
					this.$api.msg('请输入店主姓名')
					return false;
				}
				if (!this.mobile) {
					this.$api.msg('请输入店主联系方式')
					return false;
				}

				let coverImg = (this.cover_img == '' || this.cover_img === '/static/img/videos/WechatI.png') ? '' :
					this.cover_img;
				if (coverImg == '') {
					this.$api.msg('请上传封面图')
					return false;
				}

				let DataS = this.VideosData
				// if (!DataS) {
				// 	this.$api.msg('请上传资源')
				// 	return false;
				// }

				let res = await this.$myRequest({
					url: '/business_add',
					methods: "POST",
					data: {
						token: uni.getStorageSync('token'),
						name: this.name,
						owner: this.owner,
						mobile: this.mobile,
						introduce: this.introduce,
						data: DataS,
						cover_img: coverImg
					}
				})
				// console.log(res);
				this.$api.msg(res.data.msg)
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/business/lists'
					})
				}, 1500)
			},
		}
	}
</script>
<style lang='scss'>
	page {
		background: #f1f1f1;
	}

	.row {
		display: flex;
		align-items: center;
		position: relative;
		padding: 20rpx;
		height: 100%;
		background: #fff;
		border-bottom: 1rpx solid #e5e5e5;

		// margin-top: 10rpx;
		.tit {
			flex-shrink: 0;
			width: 140upx;
			font-size: 30upx;
			color: #303133;
			text-align-last: justify;
			margin-right: 10px;
		}

		.input {
			flex: 1;
			font-size: 30upx;
			color: #303133;
		}

		.icon-shouhuodizhi {
			font-size: 36upx;
			color: #909399;
		}
	}

	.default-row {
		margin-top: 20upx;

		.tit {
			flex: 1;
		}

		switch {
			transform: translateX(16upx) scale(.9);
		}
	}

	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: 32upx;
		letter-spacing: 4upx;
		color: #fff;
		background-color: #e80909;
		border-radius: 50upx;
		box-shadow: 1px 2px 5px #dadada;
	}
</style>